<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap/bootstrap-theme.min.css">
<script src="jquery/jquery-1.11.3.min.js"></script>
<script src="bootstrap/bootstrap.min.js"></script>
</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-xs-12">
				<form class="form-horizontal">
					<h2 class="form-signin-heading">美的优惠券券秒杀（灵活版）</h2>
					<div class="form-group row">
					    <label for="inputEmail" class="col-xs-2 control-label">账号：</label> 
					    <div class="col-xs-10">
					    	<input type="text" id="phone" class="form-control" required autofocus> 
					    </div>
				  	</div>
				  	<div class="form-group row">
					    <label for="inputPassword" class="col-xs-2 control-label">密码：</label> 
					    <div class="col-xs-10">
					    	<input type="password" id="password" class="form-control" required>
					    </div>
				  	</div>
				  	<div class="form-group row">
				  		<label class="col-xs-2 control-label">开始时间：</label> 
			  			<span class="col-xs-1">
						    <input type="number" class="form-control" id="hour" value="09" required>
						</span>
						<h5 class="col-xs-1">时</h5>
						<span class="col-xs-1">
						    <input type="number" class="form-control" id="minute" value="59" required>
						</span>
						<h5 class="col-xs-1">分</h5>
						<span class="col-xs-1">
						    <input type="number" class="form-control" id="second" value="59" required>
						</span>
						<h5 class="col-xs-1">秒</h5>
						<span class="col-xs-1">
						    <input type="number" class="form-control" id="millisecond" value="850" required>
						</span>
						<h5 class="col-xs-2">毫秒(0~999)</h5>
				  	</div>
				  	<div class="form-group row">
					    <label for="couponId" class="col-xs-2 control-label">券ID：</label> 
					    <div class="col-xs-10">
					    	<input type="text" id="couponId" class="form-control" required>
					    </div>
				  	</div>
					<div class="form-group row">
				      		<button type="button" id="startBtn" class="btn btn-default col-xs-2 col-xs-offset-3">开始</button>
				      		<button type="button" id="stopBtn" class="btn btn-default col-xs-2 col-xs-offset-1">结束</button>
				  	</div>
				  	<div class="form-group row">
				  		<span class="col-xs-10 col-xs-offset-2">
				  			<textarea id="console" class="form-control" rows="9"></textarea>
				  		</span>
				  	</div>
				</form>
			</div>
		</div>
		<div class="row">
			<h5 class="col-xs-4 col-xs-offset-8" style="color: red;">技术支持：唐家智  QQ 307913899</h5>
		</div>
	</div>
<script type="text/javascript">
$(function(){
	$("#startBtn").click(function(){
		var phone = $("#phone").val();
		var password = $("#password").val();
		var time = add0str($("#hour").val())+":"+add0str($("#minute").val())+":"+add0str($("#second").val())+"."+$("#millisecond").val();
		var couponId = $("#couponId").val();
		js2Java.start(phone, password, time, couponId);
	});
	
	$("#stopBtn").click(function(){
		js2Java.stop();
	});
});

function add0str(str){
	if(str!=null && str.length==1){
		return "0"+str;
	}
	return str;
}

//控制台输出
function printlnConsole(str){
	var consoleStr = $("#console").val();
	if(consoleStr == null){
		consoleStr = "";
	}
	if(str != null && str != ""){
		consoleStr = str + "\n" + consoleStr;
	}
	$("#console").val(consoleStr);
}
setInterval(function(){
	var str = js2Java.pullMessage();
	printlnConsole(str);
},1000);
</script>
</body>
</html>
